home *** CD-ROM | disk | FTP | other *** search
- unit Utest;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Format, StdCtrls, ExtCtrls, Gauges, DOSInfo;
-
- type
- TForm1 = class(TForm)
- AbortButton: TButton;
- Label2: TLabel;
- Label3: TLabel;
- WhichDrive: TComboBox;
- SizeBox: TComboBox;
- QuickFormat: TCheckBox;
- LabelName: TEdit;
- Label4: TLabel;
- Gauge1: TGauge;
- Panel1: TPanel;
- FormatButton: TButton;
- Label5: TLabel;
- procedure FormatButtonClick(Sender: TObject);
- procedure AbortButtonClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure WhichDriveChange(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure MyProgressHook (percent: Integer); far;
- begin
- Form1.Gauge1.Progress := percent;
- end;
-
- procedure TForm1.FormatButtonClick(Sender: TObject);
- var
- err, sz: Integer;
- str: String;
- begin
- Progress := MyProgressHook;
-
- Screen.Cursor := crHourGlass;
- AbortButton.Enabled := True;
- FormatButton.Enabled := False;
-
- if QuickFormat.Checked then sz := -1
- else sz := LongInt (SizeBox.Items.Objects [SizeBox.ItemIndex]);
- err := FormatDisk (WhichDrive.ItemIndex + 1, sz);
- Screen.Cursor := crDefault;
-
- if err <> 0 then
- begin
- str := SysUtils.Format ('Call to FormatDisk failed %d', [err]);
- MessageDlg (str, mtError, [mbOK], 0);
- end
- else
- begin
- if LabelName.Text <> '' then
- SetDriveLabel (WhichDrive.ItemIndex + 1, LabelName.Text);
- MessageDlg ('Disk has been successfully formatted', mtInformation, [mbOK], 0);
- end;
-
- Gauge1.Progress := 0;
- AbortButton.Enabled := False;
- FormatButton.Enabled := True;
- end;
-
- procedure TForm1.AbortButtonClick(Sender: TObject);
- begin
- fAbort := True;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- const
- DriveNames: array [0..1] of String [10] = ( 'Drive A:', 'Drive B:' );
- var
- i: Integer;
- begin
- { Initialise WhichDrive combo-box }
- for i := 0 to GetFloppyDriveCount - 1 do
- WhichDrive.Items.Add (DriveNames [i]);
- WhichDrive.ItemIndex := 0;
- WhichDriveChange (Sender);
- end;
-
- procedure TForm1.WhichDriveChange(Sender: TObject);
- var
- driveSize: Integer;
-
- procedure AddSize (start, stop: Integer);
- const
- Names: array [0..4] of String [15] = (
- '360 KBytes', '1.2 MBytes', '720 KBytes',
- '1.44 MBytes', '2.88 MBytes' );
- var
- i: Integer;
- begin
- for i := start downto stop do
- SizeBox.Items.AddObject (Names [i], TObject (i));
- end;
-
- begin
- SizeBox.Items.Clear;
- { Drive selection has changed - update SizeBox combo }
- driveSize := GetFloppyDriveType (WhichDrive.ItemIndex);
- case driveSize of
- 360: { 360 KBytes } AddSize (0, 0);
- 1200: { 1.2 MBytes } AddSize (1, 0);
- 720: { 720 KBytes } AddSize (2, 2);
- 1440: { 1.44 MBytes } AddSize (3, 2);
- 2880: { 2.88 MBytes } AddSize (4, 2);
- end;
- SizeBox.ItemIndex := 0;
- end;
-
- end.
-